package creation.builder;

import java.util.ArrayList;
import java.util.List;

/**
 * 车辆模型的抽象
 *
 * @author wangjinqiang
 * @date 2019-08-05
 */
public abstract class CarModel {
    /**
     * 各个方法的执行顺序
     */
    private List<String> sequence = new ArrayList<>();

    protected abstract void start();

    protected abstract void stop();

    protected abstract void alarm();

    protected abstract void engineBoom();

    final public void run() {
        for (int i = 0; i < sequence.size(); i++) {
            String actionName = sequence.get(i);
            if ("start".equalsIgnoreCase(actionName)) {
                this.start();
            }

            if ("stop".equalsIgnoreCase(actionName)) {
                this.stop();
            }

            if ("alarm".equalsIgnoreCase(actionName)) {
                this.alarm();
            }

            if ("engine boom".equalsIgnoreCase(actionName)) {
                this.engineBoom();
            }
        }
    }

    final public void setSequence(List<String> sequence) {
        this.sequence = sequence;
    }
}
